package com.ruoyi.web.controller.used;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.used.domain.UsedMember;
import com.ruoyi.used.service.IUsedMemberService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员等级Controller
 * 
 * @author ruoyi
 * @date 2020-07-11
 */
@Controller
@RequestMapping("/used/member")
public class UsedMemberController extends BaseController
{
    private String prefix = "used/member";

    @Autowired
    private IUsedMemberService usedMemberService;

    @RequiresPermissions("used:member:view")
    @GetMapping()
    public String member()
    {
        return prefix + "/member";
    }

    /**
     * 查询会员等级列表
     */
    @RequiresPermissions("used:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UsedMember usedMember)
    {
        startPage();
        List<UsedMember> list = usedMemberService.selectUsedMemberList(usedMember);
        return getDataTable(list);
    }

    /**
     * 导出会员等级列表
     */
    @RequiresPermissions("used:member:export")
    @Log(title = "会员等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UsedMember usedMember)
    {
        List<UsedMember> list = usedMemberService.selectUsedMemberList(usedMember);
        ExcelUtil<UsedMember> util = new ExcelUtil<UsedMember>(UsedMember.class);
        return util.exportExcel(list, "member");
    }

    /**
     * 新增会员等级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员等级
     */
    @RequiresPermissions("used:member:add")
    @Log(title = "会员等级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UsedMember usedMember)
    {
        return toAjax(usedMemberService.insertUsedMember(usedMember));
    }

    /**
     * 修改会员等级
     */
    @GetMapping("/edit/{meid}")
    public String edit(@PathVariable("meid") Long meid, ModelMap mmap)
    {
        UsedMember usedMember = usedMemberService.selectUsedMemberById(meid);
        mmap.put("usedMember", usedMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员等级
     */
    @RequiresPermissions("used:member:edit")
    @Log(title = "会员等级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UsedMember usedMember)
    {
        return toAjax(usedMemberService.updateUsedMember(usedMember));
    }

    /**
     * 删除会员等级
     */
    @RequiresPermissions("used:member:remove")
    @Log(title = "会员等级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(usedMemberService.deleteUsedMemberByIds(ids));
    }
}
